﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DocumentPropertyCondition.cs" company="Microsoft">
//   Microsoft
// </copyright>
// <summary>
//   This condition handles how to
// </summary>
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// --------------------------------------------------------------------------------------------------------------------

namespace MySemanticSearch.Web.QueryBuilder.Conditions
{
    using System;
    using System.Data.SqlClient;
    using System.Globalization;

    /// <summary>
    /// This condition handles how to filter documents by property
    /// </summary>
    public class DocumentPropertyCondition : ICondition
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentPropertyCondition"/> class.
        /// </summary>
        /// <param name="propertyName">
        /// The property name.
        /// </param>
        /// <param name="propertyValue">
        /// The property value.
        /// </param>
        public DocumentPropertyCondition(string propertyName, string propertyValue)
        {
            this.PropertyName = propertyName;
            this.PropertyValue = "'" + propertyValue + "'";
        }
        
        /// <summary>
        /// Gets or sets propertyName.
        /// </summary>
        private string PropertyName { get; set; }

        /// <summary>
        /// Gets or sets propertyValue.
        /// </summary>
        private string PropertyValue { get; set; }
        
        /// <summary>
        /// Builds a condition with the propertyName and Value
        /// </summary>
        /// <returns>
        /// A condition to filter by Property
        /// </returns>
        public string GetCondition()
        {
            return String.Format(CultureInfo.InvariantCulture, App_Data.SqlConditions.ByPropertyCondition, this.PropertyName, this.PropertyValue);
        }
    }
}